package group2assignone.ucm.manager;

import group2assignone.dao.MyDAO;
import group2assignone.model.Flight;
import group2assignone.ucm.UCController;
import group2assignone.ucm.UCStartup;
import group2assignone.view.manager.EditFlightView;

/**
 * Use Case: Edit Flight Search                                             <br>
 * Pre-condition: Manager has clicked search from edit flight view.         <br>
 * Post-condition: UI is updated.                                           <br>
 * 1. System retrieves flight number of flight to edit.                     <br>
 * 2. System retrieves flight details.                                      <br>
 * 3. System updates UI to display flight details.                          <br>
 *                                                                          <br>
 * 2.a. - Flight does not exist.                                            <br>
 *      - System resets UI input fields.                                    <br>
 *      - System displays error message.                                    <br>
 * @author group2                                                           <br>
 */
public class UCEditFlightSearch implements UCController {

    private EditFlightView editView = new EditFlightView();
    private Flight f;// = new Flight();

    /**
     * sets view and flight
     * @param eView
     * @param fl
     */
    public UCEditFlightSearch(EditFlightView eView, Flight fl) {
        editView = eView;
        f = fl;
    }

    @Override
    public void run() {
        //1. System retrieves flight number of flight to edit.
        //2. System retrieves flight details.
        MyDAO coms = UCStartup.getInstance().getDAO();
        f = coms.sQLGetFlight(editView.getFlightNum());

        if (f.getFlightNum().equals(null))
        {//2.a. - Flight does not exist.
         //     - System resets UI input fields.
            editView.resetFlightNum();
         //     - System displays error message
            editView.errorFlightNum();
        } else { //3. System updates UI to display flight details.
            editView.showFlightDetails(f);
        }
    }
}
